package net.mihome.app.bean;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import net.mihome.app.bean.net.ResponsePojo;

public class ChatMsgEntity {
    private static final String TAG = ChatMsgEntity.class.getSimpleName();
    private String avatar;
    //名字
    private String name;
    //日期
    private String date;
    //聊天内容
    private String text;
    //是否为对方发来的信息
    private boolean isComMeg = true;
    
    public static ChatMsgEntity paserMap(Map map){
		ChatMsgEntity chatMsgEntity=new ChatMsgEntity();
		chatMsgEntity.setAvatar((String) map.get("avatar"));
		chatMsgEntity.setText((String) map.get("text"));
		chatMsgEntity.setName((String) map.get("name"));
		chatMsgEntity.setDate((String) map.get("time"));
		return chatMsgEntity;
    }
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public boolean getMsgType() {
        return isComMeg;
    }

    public void setMsgType(boolean isComMsg) {
    	isComMeg = isComMsg;
    }

    public ChatMsgEntity() {
    }

    public ChatMsgEntity(String name, String date, String text, boolean isComMsg) {
        this.name = name;
        this.date = date;
        this.text = text;
        this.isComMeg = isComMsg;
    }
    public static ChatMsgEntity parse(ResponsePojo responsePojo){
    	if(responsePojo!=null&&responsePojo.getData()!=null){
    		Map map=(Map) responsePojo.getData();
    		ChatMsgEntity chatMsgEntity=new ChatMsgEntity();
    		chatMsgEntity.setDate((String) map.get("create_at"));
    		chatMsgEntity.setMsgType(true);
    		chatMsgEntity.setName((String) map.get("user_name"));
    		chatMsgEntity.setText((String) map.get("content"));
			chatMsgEntity.setAvatar((String) map.get("avatar"));
    		return chatMsgEntity;
    	}else{
    		return null;
    	}
    }
    public static List<ChatMsgEntity> parseList(ResponsePojo responsePojo ){
    	List<ChatMsgEntity> list=new ArrayList<ChatMsgEntity>();
    	if(responsePojo!=null){
        	List<Map> mapList=(List<Map>) responsePojo.getData();
        	if(mapList!=null&&!mapList.isEmpty()){
        		Iterator<Map> iterator=mapList.iterator();
        		while(iterator.hasNext()){
        			Map map=iterator.next();
        			ChatMsgEntity chatMsgEntity=new ChatMsgEntity();
        			chatMsgEntity.setDate((String) map.get("create_at"));
        			chatMsgEntity.setMsgType(true);
        			chatMsgEntity.setName((String) map.get("user_name"));
        			chatMsgEntity.setText((String) map.get("content"));
        			chatMsgEntity.setAvatar((String) map.get("user_face"));
        			list.add(chatMsgEntity);
        		}
        	}
    	}
    	return list;
    }

	public String getAvatar() {
		return avatar;
	}

	public void setAvatar(String avatar) {
		this.avatar = avatar;
	}
    
}
